﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Windows.Media;
using Styx;
using Styx.Helpers;
using Styx.Common;
using Styx.CommonBot.POI;
using Styx.CommonBot;
using Styx.CommonBot.Routines;
using Styx.Pathing;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;


namespace Spriest
{
    public partial class Classname : CombatRoutine
    {
        
        #region BagItems

        public bool HealthStone()
        {
            if (gotTarget
                && Me.Combat
                && Me.HealthPercent <= SpriestSettings.myPrefs.HealthstonePercent)
            {
                WoWItem hstone = Me.BagItems.FirstOrDefault(h => h.Entry == 5512);
                if (hstone == null)
                {
                    if (HaveHealthStone != "no")
                    {
                        Logging.Write(Colors.BlanchedAlmond, "I have no Healthstone");
                        HaveHealthStone = "no";
                        return false;
                    }
                }
                if (hstone != null && hstone.CooldownTimeLeft.TotalMilliseconds <= 0)
                {
                    hstone.Use();
                    Logging.Write(Colors.BlanchedAlmond, "Using Healthstone");
                }
            }
            return false;
        }
         
        public bool myFlask()
        {
            bool useFlask = false;
            if (SpriestSettings.myPrefs.IntellectFlask == 2
                && Me.GroupInfo.IsInRaid)
            {
                useFlask = true;
            }
            if (SpriestSettings.myPrefs.IntellectFlask == 1
                && Me.IsInInstance)
            {
                useFlask = true;
            }
            if (gotTarget
                && Me.Combat 
                && useFlask
                && !FlaskBuff())
            {
                WoWItem flask = Me.BagItems.FirstOrDefault(h => h.Entry == 76085);
                if (flask == null)
                {
                    if (HaveFlasks != "no")
                    {
                        Logging.Write(Colors.Red, "I have no Intellect Flask");
                        HaveFlasks = "no";
                    }
                    return false;
                }
                if (flask != null && flask.CooldownTimeLeft.TotalMilliseconds <= 0)
                {
                    flask.Use();
                    Logging.Write(Colors.BlanchedAlmond, "Using Intellect Flask");
                    HaveFlasks = "yes";
                    return true;
                }
            }
            return false;
        }
        public bool myPotion()
        {
            bool useFlask = false;
            if (SpriestSettings.myPrefs.JadeSerpent == 2
                && Me.GroupInfo.IsInRaid)
            {
                useFlask = true;
            }
            if (SpriestSettings.myPrefs.JadeSerpent == 1
                && Me.IsInInstance)
            {
                useFlask = true;
            }
            if (Me.CurrentTarget != null
                && Me.Combat
                && useFlask)
            {
                 
                WoWItem potion = Me.BagItems.FirstOrDefault(h => h.Entry == 76093);
                 
                if (potion != null && potion.CooldownTimeLeft.TotalMilliseconds <= 0)
                {
                    potion.Use();
                    Logging.Write(Colors.BlanchedAlmond, "Using Jade Serpent potion");
                    HavePotionBuff = "yes";
                    return true;
                }
                if (potion == null)
                {
                    if (HavePotionBuff != "no")
                    {
                        Logging.Write(Colors.Red, "I have no Jade Serpent potions");
                        HavePotionBuff = "no";
                    }
                    return false;
                }

            }
            return false;
        }
        public bool myHealthPotion()
        {
            if (Me.CurrentTarget != null
                && Me.Combat)
            {
                WoWItem bagPotion = HealDrink();
                WoWItem potion = Me.BagItems.FirstOrDefault(h => h.Entry == bagPotion.Entry);
                if (potion == null)
                {
                    if (HaveHealPotions != "no")
                    {
                        Logging.Write(Colors.Red, "I have no Healing Potions");
                        HaveHealPotions = "no";
                    }
                    return false;
                }
                if (potion != null && potion.CooldownTimeLeft.TotalMilliseconds <= 0)
                {
                    potion.Use();
                    Logging.Write(Colors.BlanchedAlmond, "Using " + bagPotion.Name);
                    HaveHealPotions = "yes";
                    return true;
                }
            }
            return false;
        }
        public WoWItem HealDrink()
        {
            List<WoWItem> Items = ObjectManager.GetObjectsOfType<WoWItem>(false);
            foreach (WoWItem Item in Items)
            {
                switch (Item.Entry)
                {
                    case 76094: return Item; //Alchemist's Rejuvenation Potion
                    case 76097: return Item; // Master Healing Potion
                    case 80040: return Item; //Endless Master Healing Potion
                    case 63144: return Item; //Baradin's Wardens Healing Potion
                    case 64994: return Item; //Hellscream's Reach Healing Potion
                    case 57193: return Item; //Mighty Rejuvenation Potion
                    case 57191: return Item; //Mythical Healing Potion
                    case 63300: return Item; //Rogue's Draught
                    case 67145: return Item; //Draught of War
                    case 33447: return Item; //Runic Healing Potion
                    case 40077: return Item; //Crazy Alchemist's Potion
                    case 40081: return Item; //Potion of Nightmares
                    case 40087: return Item; //Powerful Rejuvenation Potion
                    case 41166: return Item; //Runic Healing Injector
                    case 43569: return Item; //Endless Healing Potion
                    case 22850: return Item; //Super Rejuvenation Potion
                    case 34440: return Item; //Mad Alchemist's Potion
                    case 39671: return Item; //Resurgent Healing Potion
                    case 31838: return Item; //Major Combat Healing Potion
                    case 31839: return Item; //Major Combat Healing Potion
                    case 31852: return Item; //Major Combat Healing Potion
                    case 31853: return Item; //Major Combat Healing Potion
                    case 32784: return Item; //Red Ogre Brew
                    case 32910: return Item; //Red Ogre Brew Special
                    case 31676: return Item; //Fel Regeneration Potion
                    case 23822: return Item; //Healing Potion Injector
                    case 33092: return Item; //Healing Potion Injector
                    case 22829: return Item; //Super Healing Potion
                    case 32763: return Item; //Rulkster's Secret Sauce
                    case 32904: return Item; //Cenarion Healing Salve
                    case 32905: return Item; //Bottled Nethergon Vapor
                    case 32947: return Item; //Auchenai Healing Potion
                    case 39327: return Item; //Noth's Special Brew
                    case 43531: return Item; //Argent Healing Potion
                    case 18253: return Item; //Major Rejuvenation Potion
                    case 28100: return Item; //Volatile Healing Potion
                    case 33934: return Item; //Crystal Healing Potion
                    case 13446: return Item; //Major Healing Potion
                    case 17384: return Item; //Major Healing Draught
                    case 3928: return Item; //Superior Healing Potion
                    case 9144: return Item; //Wildvine Potion
                    case 12190: return Item; //Dreamless Sleep Potion
                    case 17349: return Item; //Superior Healing Draught
                    case 18839: return Item; //Combat Healing Potion
                    case 1710: return Item; //Greater Healing Potion
                    case 929: return Item; //Healing Potion
                    case 4596: return Item; //Discolored Healing Potion
                    case 858: return Item; //Lesser Healing Potion
                    case 118: return Item; //Minor Healing Potion
                }
            }
            return null;
        }
        #endregion BagItems
    }
}
